<?php

/*
 * Copyright 2018 zhuo bing.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace backend\components\widgets;

use Yii;
use yii\base\Widget;
use yii\helpers\Html;
use kartik\widgets\Select2;
use backend\module\content\models\ContentCategory;
use backend\models\BackendUser;

/**
 * Description of BulkMoveWidget
 *
 * @author zhuo bing
 */
class BulkMoveWidget extends Widget {

    public $controller;
    public $select2Data;
    public function run() {
        $bn = Html::a(
                        Yii::t('common', 'Move All'), ["bulk-move"], [
                    "class" => "btn btn-danger btn-xs",
                    'role' => 'modal-remote-bulk-move',
                    'data-confirm' => false, 'data-method' => false, // for overide yii data api
                    'data-request-method' => 'post',
                    'data-confirm-title' => Yii::t('common', 'Are you sure?'),
                    'data-confirm-message' => Yii::t('common', 'Are you sure want to Move this item'),
                        ]
        );
        $select2Data = $this->select2Data;
        $select2 = Select2::widget([
                    'name' => 'target_catid',
                    'data' => $select2Data,
                    'size' => 'sm',
                    'options' => ['placeholder' => Yii::t('common', 'Select ...')],
                    'pluginOptions' => [
                        'allowClear' => true
                    ],
        ]);
        $content = "<div class='bulk-move pull-left'><div class='pull-left'>$bn</div>"."<div class='pull-left select'>$select2</div></div>";
        return $content;
    }
    /**
     * 输出标准的select控件
     * @return type
     */
    public function showSelect(){
        $select2Data = ContentCategory::getSubNodeModel(
                        ContentCategory::getAllData(BackendUser::getParentUserId()),
                        'article'
                    );
        $select = "<select class='form-control' name='target_catid'>";
        foreach($select2Data as $k => $v){
            $select.="<option value='$k'>$v</option>";
        }
        return $select.'</select>';
    }
}
